home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / pascal / pnl010.zip / MDP6.PAS < prev    next >
Pascal/Delphi Source File  |  1992-03-01  |  3KB  |  89 lines

  1. program mdp6;
  2.  
  3. {Program to accompany article in issue #10 of the Pascal NewsLetter.       }
  4. {Author: Mitch Davis, (3:634/384.6) +61-3-890-2062.                        }
  5.  
  6. {After reading the file specified on the command line, this program will   }
  7. {instantly jump to any line (up to a VERY large number) you choose.        }
  8. {Note that this program uses the BigArray unit featured elsewhere in this  }
  9. {issue of PNL.  This is how it can access such HUGE files.  It uses the    }
  10. {same "array of offsets" techniques that previous programs have.           }
  11.  
  12. {$R-,S-,N+,M 16384,0,0}
  13.  
  14. uses Crt, Textutl2, DosMem, BigArray;
  15.  
  16. const TBuffSize = 20; {k}
  17.       ScreenLen = 24;
  18.       LineCount:word = 0;
  19.  
  20. type TBuffPtr  = ^TBuffType; {Text buffer stuff}
  21.      TBuffType = array [1..TBuffSize*1024] of byte; {20k text buffer}
  22.  
  23. var MaxLines:longint;
  24.     LineBank:BigArray.BigDOSArray; {This is the array object that holds}
  25.                                    {the offsets to the start of lines  }
  26.     TBuff:TBuffPtr;
  27.     LinePtr:^longint; {The linebank object will set this with a pointer to}
  28.                       {where that object is stored.                       }
  29.     Buffer:string;
  30.     Loop,LNum:word;
  31.     f:text;
  32.  
  33. procedure PrLn (var s:string);
  34.  
  35. begin
  36.   writeln (copy (s,1,79));
  37. end;
  38.  
  39. begin
  40.   {Set up text buffer}
  41.   TBuff := ptr (DosMem.Alloc (TBuffSize * 64),0); { * 64 turns K into paras}
  42.   {Initialise the line arrays}
  43.   with linebank do begin
  44.     SetElemSize (sizeof (longint));
  45.     MaxLines := GetMaxSize;
  46.     writeln ('There''s room for ',MaxLines,' lines in memory.');
  47.     Init (MaxLines);
  48.   end;
  49.   writeln ('Reading...');
  50.   assign (f,paramstr (1)); SetTextBuf (f,TBuff^); reset (f);
  51.   LineCount := 0;
  52.   while not (eof (f) or (LineCount = MaxLines)) do begin
  53.     inc (LineCount);
  54.     write (LineCount,#13);
  55.     LinePtr := LineBank.Elem (LineCount);
  56.     LinePtr^ := TextFilePos (f);
  57.     readln (f);
  58.   end;
  59.   writeln;
  60.  
  61.   clrscr;
  62.   repeat
  63.     if Linecount = 0 then begin
  64.       writeln ('File is empty.');
  65.       DosMem.Free (seg(TBuff^)); {not really needed, but here for looks.}
  66.       LineBank.Done;
  67.       halt;
  68.     end;
  69.     write ('Enter a line number (1-',LineCount,', 0 to quit): ');
  70.     readln (lnum);
  71.     if (lnum > 0) and (lnum <= LineCount) then begin
  72.       clrscr;
  73.       LinePtr := LineBank.Elem (Lnum);
  74.       TextSeek (f,LinePtr^);
  75.       loop := 0;
  76.       repeat
  77.         readln (f,buffer);
  78.         prLn (buffer);
  79.         inc (loop);
  80.       until (loop = ScreenLen) or eof (f);
  81.       repeat until keypressed;
  82.     end;
  83.   until lnum = 0;
  84.   close (f);
  85.   DosMem.Free (seg(TBuff^));
  86.   LineBank.Done;
  87. end.
  88.  
  89.